package com.jackeys.piaems.dao.impl;

import com.jackeys.piaems.dao.UserDao;
import com.jackeys.piaems.dao.mapper.UserMapper;
import com.jackeys.piaems.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Date;
import java.util.List;

/**
 * @ClassName: UserDaoImpl
 * @Description: 用户持久层实现类
 * @Author: Jackeys
 * @Date: 2021-06-08 17:42
 * @Version: 1.0
 */
@Repository
public class UserDaoImpl implements UserDao {

    @Autowired
    private UserMapper userMapper;


    /**
     * @Name: getUserInfByAccount
     * @Description: 获取数据库用户信息，实现查询用户信息功能
     * @Param: [id]
     * @return: java.util.List<com.jackeys.piaems.entity.User>
     * @Author: Jackeys
     * @Date: 2021/6/11 13:59
     * @Version: 1.0
     */
    @Override
    public List<User> getUserInfByAccount(String account) {
        return userMapper.getUserInfByAccount(account);
    }


    /**
     * @Name: login
     * @Description: 查询数据库用户账号与密码是否一致，实现登陆功能
     * @Param: [account, password]
     * @return: com.jackeys.piaems.entity.User
     * @Author: Jackeys
     * @Date: 2021/6/11 13:59
     * @Version: 1.0
     */
    @Override
    public List<User> login(String account, String password) {
        return userMapper.login(account, password);
    }


    /**
     * @Name: register
     * @Description: 添加数据库用户信息，实现登陆功能
     * @Param: [account, password, email]
     * @return: boolean
     * @Author: Jackeys
     * @Date: 2021/6/11 14:00
     * @Version: 1.0
     */
    @Override
    public Boolean register(String account, String password, String email) {
        return userMapper.register(account, password, email);
    }


    /**
     * @Name: forget
     * @Description: 修改数据库用户密码，忘记密码功能
     * @Param: [account, password]
     * @return: boolean
     * @Author: Jackeys
     * @Date: 2021/6/11 14:00
     * @Version: 1.0
     */
    @Override
    public Boolean forget(String email, String password) {
        return userMapper.forget(email, password);
    }


    /**
     * @Name: isEmailConflict
     * @Description: 查询数据库邮箱是否冲突，实现邮箱唯一功能
     * @Param: [email]
     * @return: java.lang.Integer
     * @Author: Jackeys
     * @Date: 2021/6/14 20:06
     * @Version: 1.0
     */
    @Override
    public Integer isEmailConflict(String email) {
        return userMapper.isEmailConflict(email);
    }

    /**
    * @Name: updateUserInfByAccount
    * @Description: 更改数据库用户的个人信息，实现修改用户信息的功能
    * @Param: [account, name, birthday, sex, age, phone, sign, headPortrait]
    * @return: java.lang.Boolean
    * @Author: Jackeys
    * @Date: 2021/6/23 20:46
    * @Version: 1.0
    */
    @Override
    public Boolean updateUserInfByAccount(String account, String name, @RequestBody Date birthday, String sex, Integer age, String phone, String sign, String headPortrait) {
        return userMapper.modifyUserInf(account,name,birthday,sex,age,phone,sign,headPortrait);
    }

    /**
    * @Name: selectHeadPortraitByAccount
    * @Description: 根据用户账号查询出头像，实现登录时展示用户头像的功能
    * @Param: [account]
    * @return: java.lang.String
    * @Author: Jackeys
    * @Date: 2021/6/26 5:46
    * @Version: 1.0
    */
    @Override
    public String selectHeadPortraitByAccount(String account) {
        return userMapper.selectHeadPortraitByAccount(account);
    }
}
